﻿/*
* ============================================================================
* GNU Lesser General Public License
* ============================================================================
*
* BYDAN - Free Java BYDAN library.
* Copyright (C) 2008 
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
* 
* BYDAN Corporation
*/
package ByDan.AulaVirtual.Business.Entities;

import java.util.ArrayList;
import ByDan.Framework.AulaVirtual.Business.Entities.GeneralEntity;
import ByDan.Framework.AulaVirtual.Business.Entities.Mensajes;
import ByDan.Framework.AulaVirtual.Utils.ParameterDbType;
import ByDan.Framework.AulaVirtual.Utils.ParameterType;
import ByDan.Framework.AulaVirtual.Utils.ParametersMaintenance;
import ByDan.Framework.AulaVirtual.Utils.ParameterMaintenance;
import ByDan.Framework.AulaVirtual.Utils.ParameterValue;
import ByDan.Framework.AulaVirtual.Utils.ParametersType;
import java.sql.*;

public class Pregunta extends GeneralEntity
{
	static  String strTableName="Pregunta";
		
	public static String getStrTableName() 
	{
		return strTableName;
	}

	public static void setStrTableName(String strTableName) 
	{
		Pregunta.strTableName = strTableName;
	}
	
	public static String getColumnNameId()
	{
		return "id";
	}
	
	public Pregunta preguntaOriginal;
	
	public Pregunta getPreguntaOriginal()
	{
		return preguntaOriginal;
	}
	
	public  void  setPreguntaOriginal(Pregunta pregunta)
	{
		try
		{
			preguntaOriginal=pregunta;
		}
		catch(Exception ex)
		{
			;
		}
	}
	
	
	
	
	Test relationship_test;
	 
	
	public Test getRelationship_Test()
	{
		return relationship_test;
	}

	
	
	public  void  setRelationship_Test(Test test)
	{
		try
		{
			relationship_test=test;
		}
		catch(Exception ex)
		{
			;
		}
	}


	
	
	ArrayList<Respuesta> relationship_respuestas;
	
	
	public ArrayList<Respuesta> getRelationship_respuestas()
	{
		return relationship_respuestas;
	}

	
	
	public  void  setRelationship_Respuesta(ArrayList<Respuesta> respuestas)
	{
		try
		{
			this.relationship_respuestas=respuestas;
		}
		catch(Exception ex)
		{
			;
		}
	}

	
	private static Boolean blnDeleteCascade=false;
	private static String QueryInsert="insert into aulavirtualme_dbo.Pregunta set ISACTIVE=?,ISEXPIRED=?,VERSIONROW=CURRENT_TIMESTAMP,IDTEST=?,PREGUNTA=?,NUMERO=?,ESTADO=?";
	private static String QueryUpdate="update aulavirtualme_dbo.Pregunta set ISACTIVE=?,ISEXPIRED=?,VERSIONROW=CURRENT_TIMESTAMP,IDTEST=?,PREGUNTA=?,NUMERO=?,ESTADO=? where id=? AND versionRow=?";
	private static String QueryDelete="delete from aulavirtualme_dbo.Pregunta where id=?";
	public static String QuerySelect="select aulavirtualme_dbo.Pregunta.id,aulavirtualme_dbo.Pregunta.isActive,aulavirtualme_dbo.Pregunta.isExpired,aulavirtualme_dbo.Pregunta.versionRow,aulavirtualme_dbo.Pregunta.IDTEST,aulavirtualme_dbo.Pregunta.PREGUNTA,aulavirtualme_dbo.Pregunta.NUMERO,aulavirtualme_dbo.Pregunta.ESTADO from aulavirtualme_dbo.Pregunta";
	 
	Long field_bigIdTest;
	String field_strPregunta;
	Integer field_intNumero;
	Boolean field_bitEstado;
				
	public Pregunta ()
    {
		super();		
 		field_bigIdTest=-1L;
 		field_strPregunta="";
 		field_intNumero=-1;
 		field_bitEstado=false;
		
		
		relationship_test=new Test();
		
		
		relationship_respuestas=new ArrayList<Respuesta>();
		
		super.setQueryInsert(QueryInsert);
		super.setQueryUpdate(QueryUpdate);
		super.setQueryDelete(QueryDelete);
		super.setQuerySelect(QuerySelect);
		
    } 
	
	public static Boolean getBlnDeleteCascade() 
	{
		return blnDeleteCascade;
	}

	public static void setBlnDeleteCascade(Boolean blnDeleteCascade) 
	{
		Pregunta.blnDeleteCascade = blnDeleteCascade;
	}
	
	public static String getTableName()
    {
         return "aulavirtualme_dbo.Pregunta";
    }
	
    
	public static String getColumnNameidTest()
	{
		return "idTest";
	}
    
	public static String getColumnNamePregunta()
	{
		return "Pregunta";
	}
    
	public static String getColumnNameNumero()
	{
		return "Numero";
	}
    
	public static String getColumnNameEstado()
	{
		return "Estado";
	}
     
    
	public Long getField_bigIdTest()
	{
		return field_bigIdTest;
	}
    
	public String getField_strPregunta()
	{
		return field_strPregunta;
	}
    
	public Integer getField_intNumero()
	{
		return field_intNumero;
	}
    
	public Boolean getField_bitEstado()
	{
		return field_bitEstado;
	}
	
    
	public void setField_bigIdTest(Long newField_bigIdTest)throws Exception
	{
		try
		{
			if(this.field_bigIdTest!=newField_bigIdTest)
			{
				if(newField_bigIdTest==null)
				{
					throw new Exception(this.getTableName()+":"+ Mensajes.getMensajeExcepcionValorNulo()+" en columna "+Pregunta.getColumnNameidTest());
				}

				this.field_bigIdTest=newField_bigIdTest;
				this.setIsChanged(true);
			}
		}
		catch(Exception ex)
		{
			throw ex;
		}
	}
    
	public void setField_strPregunta(String newField_strPregunta)throws Exception
	{
		try
		{
			if(this.field_strPregunta!=newField_strPregunta)
			{
				if(newField_strPregunta==null)
				{
					throw new Exception(this.getTableName()+":"+ Mensajes.getMensajeExcepcionValorNulo()+" en columna "+Pregunta.getColumnNamePregunta());
				}

				this.field_strPregunta=newField_strPregunta;
				this.setIsChanged(true);
			}
		}
		catch(Exception ex)
		{
			throw ex;
		}
	}
    
	public void setField_intNumero(Integer newField_intNumero)throws Exception
	{
		try
		{
			if(this.field_intNumero!=newField_intNumero)
			{
				if(newField_intNumero==null)
				{
					throw new Exception(this.getTableName()+":"+ Mensajes.getMensajeExcepcionValorNulo()+" en columna "+Pregunta.getColumnNameNumero());
				}

				this.field_intNumero=newField_intNumero;
				this.setIsChanged(true);
			}
		}
		catch(Exception ex)
		{
			throw ex;
		}
	}
    
	public void setField_bitEstado(Boolean newField_bitEstado)throws Exception
	{
		try
		{
			if(this.field_bitEstado!=newField_bitEstado)
			{
				if(newField_bitEstado==null)
				{
					throw new Exception(this.getTableName()+":"+ Mensajes.getMensajeExcepcionValorNulo()+" en columna "+Pregunta.getColumnNameEstado());
				}

				this.field_bitEstado=newField_bitEstado;
				this.setIsChanged(true);
			}
		}
		catch(Exception ex)
		{
			throw ex;
		}
	}
		
	public  void BuildParametersMaintenance(ParameterDbType newDbType,ParametersType parametersType) throws Exception
	{
		try
		{
			ParametersMaintenance parametersMaintenance=super.getParametersMaintenance();		
			ArrayList<ParameterMaintenance> parametersTemp=new ArrayList<ParameterMaintenance>();
			ParameterMaintenance parameterMaintenance;
			ParameterValue<Long> parameterMaintenanceValueId;
			
				if(!parametersType.equals(ParametersType.DELETE))
				{		
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(1);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.BOOLEAN);
					ParameterValue<Boolean> parameterMaintenanceValueIsactive=new ParameterValue<Boolean>();
					parameterMaintenanceValueIsactive.setValue(this.getIsActive());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueIsactive);
					parametersTemp.add(parameterMaintenance);
					
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(2);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.BOOLEAN);
					ParameterValue<Boolean> parameterMaintenanceValueIsexpired=new ParameterValue<Boolean>();
					parameterMaintenanceValueIsexpired.setValue(this.getIsExpired());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueIsexpired);
					parametersTemp.add(parameterMaintenance);
					
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(3);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.LONG);
					ParameterValue<Long> parameterMaintenanceValueIdTest=new ParameterValue<Long>();
					parameterMaintenanceValueIdTest.setValue(this.getField_bigIdTest());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueIdTest);
					parametersTemp.add(parameterMaintenance);
					
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(4);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.STRING);
					ParameterValue<String> parameterMaintenanceValuePregunta=new ParameterValue<String>();
					parameterMaintenanceValuePregunta.setValue(this.getField_strPregunta());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValuePregunta);
					parametersTemp.add(parameterMaintenance);
					
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(5);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.INT);
					ParameterValue<Integer> parameterMaintenanceValueNumero=new ParameterValue<Integer>();
					parameterMaintenanceValueNumero.setValue(this.getField_intNumero());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueNumero);
					parametersTemp.add(parameterMaintenance);
					
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(6);		
					parameterMaintenance.setParameterMaintenanceType(ParameterType.BOOLEAN);
					ParameterValue<Boolean> parameterMaintenanceValueEstado=new ParameterValue<Boolean>();
					parameterMaintenanceValueEstado.setValue(this.getField_bitEstado());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueEstado);
					parametersTemp.add(parameterMaintenance);
					
						if(parametersType.equals(ParametersType.UPDATE))
						{					
							parameterMaintenance=new ParameterMaintenance();
							parameterMaintenance.setOrder(7);
							parameterMaintenance.setParameterMaintenanceType(ParameterType.LONG);
							parameterMaintenanceValueId=new ParameterValue<Long>();
							parameterMaintenanceValueId.setValue(this.getId());
							parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueId);		
							parametersTemp.add(parameterMaintenance);
							
							parameterMaintenance=new ParameterMaintenance();
							parameterMaintenance.setOrder(8);
							parameterMaintenance.setParameterMaintenanceType(ParameterType.TIMESTAMP);
							ParameterValue<Timestamp> parameterMaintenanceValueVersionRow=new ParameterValue<Timestamp>();
							parameterMaintenanceValueVersionRow.setValue(this.getVersionRow());
							parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueVersionRow);		
							parametersTemp.add(parameterMaintenance);					
						}
				}
				else
				{
					parameterMaintenance=new ParameterMaintenance();
					parameterMaintenance.setOrder(1);
					parameterMaintenance.setParameterMaintenanceType(ParameterType.LONG);
					parameterMaintenanceValueId=new ParameterValue<Long>();
					parameterMaintenanceValueId.setValue(this.getId());
					parameterMaintenance.setParameterMaintenanceValue(parameterMaintenanceValueId);		
					parametersTemp.add(parameterMaintenance);
				}
			
			parametersMaintenance= new ParametersMaintenance();
			parametersMaintenance.setDbType(newDbType);
			parametersMaintenance.setParametersMaintenance(parametersTemp);
			super.setParametersMaintenance(parametersMaintenance);		
		}
		catch(Exception ex)
		{
			throw ex;
		}
	}
}
